<%@ taglib prefix="spring-tags" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="spring-form" uri="http://www.springframework.org/tags/form"%>
<%@ page
    import="org.jiscinvolve.astrodabis.barberry.control.Paths"
    import="org.jiscinvolve.astrodabis.barberry.control.ObjectData"
    import="org.jiscinvolve.astrodabis.barberry.control.RequestData"
    import="org.jiscinvolve.astrodabis.barberry.common.core.Account"
    import="org.jiscinvolve.astrodabis.barberry.common.core.Tag"
    import="org.jiscinvolve.astrodabis.barberry.common.core.Job"
    import="org.jiscinvolve.astrodabis.barberry.common.core.Job.AnnotType"
    import="org.jiscinvolve.astrodabis.barberry.common.data.RowTag"
    import="org.jiscinvolve.astrodabis.barberry.common.data.JoinTag"
    session="true"
%><%
ObjectData<Job> data = (ObjectData<Job>) request.getAttribute(
    RequestData.MODEL_ATTRIB
    ) ;
Account actor = data.actor();
Job job  = data.object();
%>
<html>
    <head>
	    <title>AstroDAbis job <%= job.ident() %></title>
        <link href='<%= data.file("css/page.css") %>' rel='stylesheet' type='text/css'/>
    </head>
    <body>
        <%@ include file="/jsp/header.jsp" %>
        <div class='body'>
            <div class='left'>
                <%@ include file="/jsp/menu.jsp" %>
            </div>
            <div class='right'>
                <a href='<%= data.link(job) %>'>
                    <img src='<%= data.qrcode(data.link(job)) %>'/>
                </a>
            </div>
            <div class='content'>
        	    <h2>Data import <%= job.name() %></h2>
                <fieldset>
                    <legend>Details</legend>
                    <div>
                        <ul>
                            <li>
                                Owner : <a href='<%= data.link(job.owner()) %>'><%= job.owner().name() %></a>
                            </li>
                            <li>
                                Name : <%= job.name() %>
                            </li>
                            <li>
                                Status : <%= job.status() %>
                            </li>
                            <li>
                                Type : <%= job.annotType() %>
                            </li>
                            <li>
                                Started : <%= job.started() %>
                            </li>
                            <li>
                                Finished : <%= job.finished() %>
                            </li>
                            <li>
                                Row count : <%= job.count() %>
                            </li>
                            <%
                            if (job.status() == Job.Status.COMPLETED)
                                {
                                if ((job.started() != null) && (job.finished() != null))
                                    {
                                    long time = job.finished().getTime() - job.started().getTime() ;
                                    if (time > 0)
                                        {
                                        %>
                                        <li>
                                            Rows/sec : <%= (job.count() * 1000) / time %>
                                        </li>
                                        <%
                                        }
                                    }
                                }
                            %>
                        </ul>
                    </div>
                    <%
                    if ((actor != null) && (actor.equals(job.owner())))
                        {
                        %>
                        <form action='<%= data.link(job, "delete") %>'>
    			            <button type="submit">delete</button>
                        </form>
                        <%
                        }
                    %>
                </fieldset>
                <fieldset>
                    <legend>Description</legend>
                    <div>
                        <%= job.text() %>
                    </div>
                    <%
                    if ((actor != null) && (actor.equals(job.owner())))
                        {
                        %>
                        <a href='<%= data.link(job, "edit") %>'>[edit]</a>
                        <%
                        }
                    %>
                </fieldset>
                <%
                if (job.status() == Job.Status.COMPLETED)
                    {
                    %>
                    <fieldset>
                        <legend>Tags</legend>
                        <table>
                            <%
                            for (Tag tag : job.tags().select())
                                {
                                %>
                                <tr>
                                    <td>
                                        <a href="<%= data.link(tag) %>"><%= tag.name() %></a>
                                    </td>
                                    <td>
                                        <%= tag.text() %>
                                    </td>
                                </tr>
                                <%
                                }
                            %>
                        </table>
                    </fieldset>
                    <%
                    if (job.annotType() == AnnotType.SINGLE)
                        {
                        %>
                        <fieldset>
                            <legend>Row tags (limit 100)</legend>
                            <table>
                                <thead>
                                    <tr>
                                        <td>row</td>
                                        <td>tag</td>
                                        <td>value</td>
                                    </tr>
                                </thead>
                                <tbody>
                                    <%
                                    for (RowTag rowtag : job.rowtags().select(100))
                                        {
                                        %>
                                        <tr>
                                            <td>
                                                <a href="<%= data.link(rowtag) %>"><%= rowtag.row().value() %></a>
                                            </td>
                                            <td>
                                                <a href="<%= data.link(rowtag.tag()) %>"><%= rowtag.tag().name() %></a>
                                            </td>
                                            <td>
                                                <%= (rowtag.value() != null) ? rowtag.value() : "&nbsp;" %>
                                            </td>
                                        </tr>
                                        <%
                                        }
                                    %>
                                </tbody>
                            </table>
                        </fieldset>
                        <%
                        }

                    if (job.annotType() == AnnotType.JOINED)
                        {
                        %>
                        <fieldset>
                            <legend>Join tags (limit 100)</legend>
                            <table>
                                <thead>
                                    <tr>
                                        <td>join</td>
                                        <td>tag</td>
                                        <td>value</td>
                                    </tr>
                                </thead>
                                <tbody>
                                    <%
                                    for (JoinTag jointag : job.jointags().select(100))
                                        {
                                        %>
                                        <tr>
                                            <td>
                                                <a href="<%= data.link(jointag) %>">[<%= jointag.ident() %>]</a>
                                            </td>
                                            <td>
                                                <a href="<%= data.link(jointag.tag()) %>"><%= jointag.tag().name() %></a>
                                            </td>
                                            <td>
                                                <%= (jointag.value() != null) ? jointag.value() : "&nbsp;" %>
                                            </td>
                                        </tr>
                                        <%
                                        }
                                    %>
                                </tbody>
                            </table>
                        </fieldset>
                        <%
                        }
                    }
                %>
            </div>
        </div>
        <%@ include file="/jsp/footer.jsp" %>
    </body>
</html>

